﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows.Threading;
using CSharp.Libs.Koc.KernelModels;
using CSharp.Libs.Koc.Models;
using CSharp.Libs.Koc.UserControls.ItemClasses;
using CSharp.Libs.WPF;
using CSharp.Libs.WPF.UserControls;


namespace CSharp.Libs.Koc.UserControls
{
    public partial class KocReportGetterViewModel : ViewModelBase
    {
        #region declarations
        private Dispatcher _DISP = null;
        private Kernel _KRNL = null;
        private KocKernel2ViewModel _KK2VM = null;

        //private ObservableCollection<ReportListItem> _ocReports = new ObservableCollection<ReportListItem>();

        //private ReportListItem _rliSelectedReport = null;

        private PhpCommand _pcListReports = null;
        private PhpCommand _pcFetchReport = null;
        //private PhpCommand _pcDeleteCheckedReports = null;

        //private bool _fReportsListable = false;
        //private bool _fReportSelected = false;
        private string _strStatusText = "";

        //ReportList
        //private RelayCommand _rcGetReportList = null;
        //private Int32 _intReportListPageNumber = 1;
        private Int32 _intReportListPageMax = -1;

        //Report
        //private RelayCommand _rcGetReport = null;
        #endregion



        #region constructor / terminator
        public KocReportGetterViewModel(
            Dispatcher DISP,
            Kernel KRNL, 
            KocKernel2ViewModel KK2VM)
        {
            _DISP = DISP;
            _KRNL = KRNL;
            _KK2VM = KK2VM;

            _KK2VM.AfterUserChange += new KocKernel2ViewModel.AfterUserChangeEventHandler(_KK2VM_AfterUserChange);
            _KK2VM.AfterServerChange += new KocKernel2ViewModel.AfterServerChangeEventHandler(_KK2VM_AfterServerChange);

            //_initKernelControl();
            _initReportWatcher();
        }

        ~KocReportGetterViewModel()
        {
            _KRNL = null;
        }
        #endregion



        #region event handling
        void _KK2VM_AfterServerChange(object sender, ServerChangeEventArgs scea)
        {
            OnPropertyChanged("UserIsValid");
        }

        void _KK2VM_AfterUserChange(object sender, UserChangeEventArgs ucea)
        {
            OnPropertyChanged("UserIsValid");
            OnPropertyChanged("UserValidText");
        }
        #endregion



        #region private functions
        /// <summary>_setStatusText</summary>
        /// <param name="Text"></param>
        /// <history>created  08.02.2012</history>
        private void _setStatusText(
            string Text)
        {
            _DISP.Invoke((Action)delegate
            {
                _strStatusText = Text;
                OnPropertyChanged("StatusText");
            });
        }
        #endregion



        #region interface
        #region properties
        public bool UserIsValid { get { return _KK2VM.UserIsValid; } }
        public string UserValidText { get { return _KK2VM.UserValidText; } }

        public bool WriteIcomingSeedsToDisk
        {
            get
            {
                return _KRNL.SC.SaveSeedToDisk;
            }
            set
            {
                _KRNL.SC.SaveSeedToDisk = value;
            }
        }

        public string StatusText
        {
            get
            {
                return _strStatusText;
            }
        }
        #endregion

        #region methods
        #endregion
        #endregion
    }
}
